﻿@model WebLib.PagingVM

@{
    var action = string.Empty;
    var controller = string.Empty;
    var routeDic = new RouteValueDictionary();

    foreach (var routeValue in HttpContext.Current.Request.RequestContext.RouteData.Values)
    {
        if (routeValue.Key == "action")
        {
            action = routeValue.Value.ToString();
        }
        else if (routeValue.Key == "controller")
        {
            controller = routeValue.Value.ToString();
        }
        else
        {
            routeDic.Add(routeValue.Key, routeValue.Value);
        }
    }
    
    <ul class="pagination">
        <li><a href="@Url.Action(action, controller, routeDic)?page=1@Model.Parameters">&laquo;</a></li>
        <li><a href="@Url.Action(action, controller, routeDic)?page=@(Model.CurrentPage - Model.RenderPageCount < 1 ? 1 : Model.CurrentPage - Model.RenderPageCount)@Model.Parameters">&lsaquo;</a></li>
        
        @Html.PageLinkers(
            Model.CurrentPage,
            Model.PageCount,
            i => Url.Action(action, controller, routeDic) + "?page=" + i + Model.Parameters
            )
        
        <li><a href="@Url.Action(action, controller, routeDic)?page=@(Model.CurrentPage + Model.RenderPageCount > Model.PageCount ? Model.PageCount : Model.CurrentPage + Model.RenderPageCount)@Model.Parameters">&rsaquo;</a></li>
        <li><a href="@Url.Action(action, controller, routeDic)?page=@Model.PageCount@Model.Parameters">&raquo;</a></li>
    </ul>
    
    @*<div class="pagenation">
        <a href="@Url.Action(action, controller, routeDic)?page=1@Model.Parameters"><img src="/Images/page_first.gif" alt="first" /></a>
        <a href="@Url.Action(action, controller, routeDic)?page=@(Model.CurrentPage - Model.RenderPageCount < 1 ? 1 : Model.CurrentPage - Model.RenderPageCount)@Model.Parameters" class="prev"><img src="/Images/page_prev.gif" alt="prev" /></a>
        
        @Html.PageLinkers(
            Model.CurrentPage,
            Model.PageCount,
            i => Url.Action(action, controller, routeDic) + "?page=" + i + Model.Parameters
            )
        
        <a href="@Url.Action(action, controller, routeDic)?page=@(Model.CurrentPage + Model.RenderPageCount > Model.PageCount ? Model.PageCount : Model.CurrentPage + Model.RenderPageCount)@Model.Parameters" class="next"><img src="/Images/page_next.gif" alt="next" /></a>
        <a href="@Url.Action(action, controller, routeDic)?page=@Model.PageCount@Model.Parameters"><img src="/Images/page_last.gif" alt="last" /></a>
    </div>*@
}